﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using MoonSharp.Interpreter;
using UnityEngine;
using UnityEngine.Networking;

// Token: 0x0200034C RID: 844
public class IOManager : MonoBehaviour
{
	// Token: 0x17000375 RID: 885
	// (get) Token: 0x060015E2 RID: 5602 RVA: 0x0008DF3E File Offset: 0x0008C13E
	public static IOManager Instance
	{
		get
		{
			return IOManager.GetIOManager();
		}
	}

	// Token: 0x060015E3 RID: 5603 RVA: 0x0008DF48 File Offset: 0x0008C148
	public IOManager.ModelData LoadModel(string bundlePath, string modelName)
	{
		AssetBundle assetBundle = AssetBundle.LoadFromFile(bundlePath);
		if (!(assetBundle != null))
		{
			return null;
		}
		IOManager.ModelData modelData = new IOManager.ModelData();
		GameObject gameObject = assetBundle.LoadAsset(modelName + "Prefab") as GameObject;
		if (gameObject == null || gameObject.GetComponent<UsePrefab>() == null)
		{
			gameObject = (assetBundle.LoadAsset(modelName) as GameObject);
		}
		if (gameObject == null)
		{
			Debug.LogError(modelName + " could not be loaded in " + bundlePath);
			return null;
		}
		StringHolder stringHolder = assetBundle.LoadAsset(modelName + "_shaders") as StringHolder;
		if (stringHolder != null)
		{
			this.LoadModelShaders(gameObject, stringHolder.content);
		}
		else
		{
			stringHolder = (assetBundle.LoadAsset("shaders") as StringHolder);
			if (stringHolder != null)
			{
				this.LoadModelShaders(gameObject, stringHolder.content);
			}
			else
			{
				ShaderLoader.ApplyShader(gameObject, IOManager.standard2SidedShader);
			}
		}
		modelData.modelBytes = assetBundle.LoadAsset<TextAsset>(modelName + ".model.bytes");
		modelData.indexBytes = assetBundle.LoadAsset<TextAsset>(modelName + ".index.bytes");
		modelData.vertexBytes = assetBundle.LoadAsset<TextAsset>(modelName + ".vertex.bytes");
		modelData.model = gameObject;
		assetBundle.Unload(false);
		return modelData;
	}

	// Token: 0x060015E4 RID: 5604 RVA: 0x0008E094 File Offset: 0x0008C294
	private static IOManager GetIOManager()
	{
		if (IOManager._instance != null)
		{
			return IOManager._instance;
		}
		Layers.Initialize();
		IOManager._instance = new GameObject("IOManager").AddComponent<IOManager>();
		UnityEngine.Object.DontDestroyOnLoad(IOManager._instance.gameObject);
		IOManager.standard2SidedShader = Shader.Find("SB_Standard2Sided");
		return IOManager._instance;
	}

	// Token: 0x060015E5 RID: 5605 RVA: 0x0008E0F4 File Offset: 0x0008C2F4
	public void SaveFile(string filename, string content)
	{
		string path = this.folderSaves + Path.DirectorySeparatorChar + filename;
		TextWriter textWriter = new StreamWriter(path);
		textWriter.Write(content);
		textWriter.Close();
	}

	// Token: 0x060015E6 RID: 5606 RVA: 0x0008E12C File Offset: 0x0008C32C
	public string LoadFile(string filename)
	{
		if (File.Exists(filename))
		{
			string result = File.ReadAllText(filename);
			this.isLoadingData = true;
			this.dataCache = result;
			return result;
		}
		Debug.LogError("No saved scene found: " + filename);
		this.dataCache = null;
		return null;
	}

	// Token: 0x060015E7 RID: 5607 RVA: 0x0008E173 File Offset: 0x0008C373
	public string LoadCachedDataFile()
	{
		this.isLoadingData = false;
		return this.dataCache;
	}

	// Token: 0x060015E8 RID: 5608 RVA: 0x0008E184 File Offset: 0x0008C384
	private void Awake()
	{
		this.settingsConfigVersion = "1.0";
		this.hashObjects = new Dictionary<NetworkHash128, string>();
		this.hashGiantess = new Dictionary<NetworkHash128, string>();
		this.hashPlayableGiantess = new Dictionary<NetworkHash128, string>();
		this.hashPlayer = new Dictionary<NetworkHash128, string>();
		this.GiantessAssetMapping = new Dictionary<string, string>();
		this.PlayerAssetMapping = new Dictionary<string, string>();
		this.MaleMicroAssetMapping = new Dictionary<string, string>();
		this.FemaleMicroAssetMapping = new Dictionary<string, string>();
		this.ObjectAssetMapping = new Dictionary<string, string>();
		this.audioLoader = new AudioLoader();
		this.folderGTSModels = new List<string>();
		this.folderMaleNPC = new List<string>();
		this.folderFemaleNPC = new List<string>();
		this.folderPlayerModels = new List<string>();
		this.folderObjects = new List<string>();
		this.folderSounds = new List<string>();
		this.microAnimatorController = Resources.Load<RuntimeAnimatorController>("GTSAnimator");
		this.playerAnimatorController = Resources.Load<RuntimeAnimatorController>("CharacterController");
		this.gtsPlayerAnimatorController = Resources.Load<RuntimeAnimatorController>("GTSPlayer");
		this.poseAnimatorController = Resources.Load<RuntimeAnimatorController>("GTSStaticAnimator");
		this.gtsAnimatorController = Resources.Load<RuntimeAnimatorController>("GTSAnimator");
		this.poses = new HashSet<string>();
		foreach (AnimationClip animationClip in this.poseAnimatorController.animationClips)
		{
			this.poses.Add(animationClip.name);
		}
		this.posesList = new List<string>(this.poses);
		this.animationControllers = new Dictionary<string, RuntimeAnimatorController>();
		foreach (AnimationClip animationClip2 in this.gtsAnimatorController.animationClips)
		{
			if (!animationClip2.name.StartsWith("_"))
			{
				this.animationControllers[animationClip2.name] = this.gtsAnimatorController;
			}
		}
		IOManager.AddIf(this.folderGTSModels, IOManager.GetUserDirectory(Path.Combine("Models", "Giantess"), false));
		IOManager.AddIf(this.folderPlayerModels, IOManager.GetUserDirectory(Path.Combine("Models", "Player"), false));
		IOManager.AddIf(this.folderMaleNPC, IOManager.GetUserDirectory(Path.Combine("Models", "MaleNPC"), false));
		IOManager.AddIf(this.folderFemaleNPC, IOManager.GetUserDirectory(Path.Combine("Models", "FemaleNPC"), false));
		IOManager.AddIf(this.folderObjects, IOManager.GetUserDirectory(Path.Combine("Models", "Objects"), false));
		IOManager.AddIf(this.folderSounds, IOManager.GetUserDirectory("Sounds", false));
		IOManager.AddIf(this.folderGTSModels, IOManager.GetApplicationDirectory(Path.Combine("Models", "Giantess")));
		IOManager.AddIf(this.folderMaleNPC, IOManager.GetApplicationDirectory(Path.Combine("Models", "MaleNPC")));
		IOManager.AddIf(this.folderFemaleNPC, IOManager.GetApplicationDirectory(Path.Combine("Models", "FemaleNPC")));
		IOManager.AddIf(this.folderPlayerModels, IOManager.GetApplicationDirectory(Path.Combine("Models", "Player")));
		IOManager.AddIf(this.folderObjects, IOManager.GetApplicationDirectory(Path.Combine("Models", "Objects")));
		IOManager.AddIf(this.folderSounds, IOManager.GetApplicationDirectory("Sounds"));
		XmlResourceSettingReader xmlResourceSettingReader = new XmlResourceSettingReader(true);
		this.folderSaves = xmlResourceSettingReader.SavePath;
		this.folderScreenshots = xmlResourceSettingReader.ScreenShotPath;
		this.folderConfig = xmlResourceSettingReader.ConfigPath;
		if (string.IsNullOrEmpty(this.folderSaves))
		{
			this.folderSaves = IOManager.GetUserDirectory("Saves", true);
		}
		if (string.IsNullOrEmpty(this.folderScreenshots))
		{
			this.folderScreenshots = IOManager.GetUserDirectory("Screenshots", true);
		}
		if (string.IsNullOrEmpty(this.folderConfig))
		{
			this.folderConfig = IOManager.GetUserDirectory("Config", true);
		}
		this.folderGTSModels.AddRange(xmlResourceSettingReader.GiantessPaths);
		this.folderMaleNPC.AddRange(xmlResourceSettingReader.MaleNpcPaths);
		this.folderFemaleNPC.AddRange(xmlResourceSettingReader.FemaleNpcPaths);
		this.folderPlayerModels.AddRange(xmlResourceSettingReader.PlayerModelPaths);
		this.folderObjects.AddRange(xmlResourceSettingReader.ObjectPaths);
		this.folderSounds.AddRange(xmlResourceSettingReader.SoundPaths);
		List<IOManager.AssetLocationWrapper> fileList = IOManager.GetFileList(this.folderGTSModels);
		List<IOManager.AssetLocationWrapper> fileList2 = IOManager.GetFileList(this.folderPlayerModels);
		List<IOManager.AssetLocationWrapper> fileList3 = IOManager.GetFileList(this.folderMaleNPC);
		List<IOManager.AssetLocationWrapper> fileList4 = IOManager.GetFileList(this.folderFemaleNPC);
		List<IOManager.AssetLocationWrapper> fileList5 = IOManager.GetFileList(this.folderObjects);
		this.playerModelList = this.GetListMicroModels(fileList2, this.PlayerAssetMapping);
		this.maleMicroList = this.GetListMicroModels(fileList3, this.MaleMicroAssetMapping);
		this.femaleMicroList = this.GetListMicroModels(fileList4, this.FemaleMicroAssetMapping);
		this.femaleMicroThumbnailList = this.GetThumbnails(fileList4, ".micro", this.FemaleMicroAssetMapping);
		this.maleMicroThumbnailList = this.GetThumbnails(fileList3, ".micro", this.MaleMicroAssetMapping);
		foreach (string text in this.playerModelList)
		{
			this.hashPlayer[ObjectManager.GetHash(text)] = text;
		}
		this.gtsModelList = this.GetGiantessModelList(fileList);
		this.objectList = this.GetObjectsModelList(fileList5);
		GameObject[] array = Resources.LoadAll<GameObject>("Stuff");
		foreach (GameObject prefab in array)
		{
			ClientScene.RegisterPrefab(prefab);
		}
		base.StartCoroutine(this.LoadSoundFiles());
	}

	// Token: 0x060015E9 RID: 5609 RVA: 0x0008E728 File Offset: 0x0008C928
	public static List<IOManager.AssetLocationWrapper> GetFileList(List<string> folders)
	{
		List<IOManager.AssetLocationWrapper> list = new List<IOManager.AssetLocationWrapper>();
		foreach (string text in folders)
		{
			if (Directory.Exists(text.Trim()))
			{
				list.AddRange(IOManager.GetFileList(text.Trim()));
			}
			else
			{
				Debug.LogError("Directory '" + text.Trim() + "' dosen't exist");
			}
		}
		return list;
	}

	// Token: 0x060015EA RID: 5610 RVA: 0x0008E7C0 File Offset: 0x0008C9C0
	public static List<IOManager.AssetLocationWrapper> GetFileList(string folder)
	{
		string[] directories = Directory.GetDirectories(folder);
		List<IOManager.AssetLocationWrapper> list = new List<IOManager.AssetLocationWrapper>();
		foreach (string folder2 in directories)
		{
			List<IOManager.AssetLocationWrapper> fileList = IOManager.GetFileList(folder2);
			foreach (IOManager.AssetLocationWrapper item in fileList)
			{
				list.Add(item);
			}
		}
		string[] files = Directory.GetFiles(folder);
		foreach (string value in files)
		{
			list.Add(new IOManager.AssetLocationWrapper(value, folder));
		}
		return list;
	}

	// Token: 0x060015EB RID: 5611 RVA: 0x0008E88C File Offset: 0x0008CA8C
	public void SaveScreenshot()
	{
		string str = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
		string text = "Screenshot " + str + ".png";
		ScreenCapture.CaptureScreenshot(this.folderScreenshots + Path.DirectorySeparatorChar + text);
		Debug.Log("Taken Screenshot: " + text);
	}

	// Token: 0x060015EC RID: 5612 RVA: 0x0008E8E8 File Offset: 0x0008CAE8
	public void Save360Screenshot()
	{
		string str = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
		string text = "360_Screenshot " + str;
		GameController.Instance.panorama.CaptureScreenshotAsync(this.folderScreenshots + Path.DirectorySeparatorChar, text);
		Debug.Log("Taken Screenshot: " + text);
	}

	// Token: 0x060015ED RID: 5613 RVA: 0x0008E949 File Offset: 0x0008CB49
	public List<GameObject> GetMaleMicroModels()
	{
		return this.SearchMicroModels(this.folderMaleNPC, this.maleMicroList, this.MaleMicroAssetMapping);
	}

	// Token: 0x060015EE RID: 5614 RVA: 0x0008E963 File Offset: 0x0008CB63
	public List<GameObject> GetFemaleMicroModels()
	{
		return this.SearchMicroModels(this.folderFemaleNPC, this.femaleMicroList, this.FemaleMicroAssetMapping);
	}

	// Token: 0x060015EF RID: 5615 RVA: 0x0008E980 File Offset: 0x0008CB80
	private List<GameObject> SearchMicroModels(List<string> folders, List<string> microList, Dictionary<string, string> assetCache)
	{
		List<GameObject> list = new List<GameObject>();
		foreach (string folder in folders)
		{
			list.AddRange(this.SearchMicroModels(folder, microList.ToArray(), assetCache));
		}
		return list;
	}

	// Token: 0x060015F0 RID: 5616 RVA: 0x0008E9EC File Offset: 0x0008CBEC
	private List<GameObject> SearchMicroModels(string folder, string[] microList, Dictionary<string, string> assetCache)
	{
		List<GameObject> list = new List<GameObject>();
		foreach (string text in microList)
		{
			string[] array = text.Split(new char[]
			{
				Path.DirectorySeparatorChar
			});
			string text2 = array[array.Length - 2];
			string text3 = array[array.Length - 1];
			string key = Path.Combine(text2, text3);
			string text4 = assetCache[key];
			string bundlePath = Path.Combine(text4, text2);
			IOManager.ModelData modelData = this.LoadModel(bundlePath, text3.Replace(".micro", string.Empty));
			if (modelData != null && folder == text4)
			{
				modelData.model.name = text;
				IOManager.SetRenderingLayer(modelData.model, Layers.microLayer);
				list.Add(modelData.model);
			}
		}
		return list;
	}

	// Token: 0x060015F1 RID: 5617 RVA: 0x0008EAC8 File Offset: 0x0008CCC8
	public string[] GetListLoadableSaveFiles()
	{
		string[] array = null;
		string[] array2 = null;
		string userDirectory = IOManager.GetUserDirectory("Saves", false);
		if (userDirectory != null)
		{
			array = Directory.GetFileSystemEntries(userDirectory);
		}
		string applicationDirectory = IOManager.GetApplicationDirectory("Saves");
		if (applicationDirectory != null)
		{
			array2 = Directory.GetFileSystemEntries(applicationDirectory);
		}
		string text = this.folderSaves;
		string[] array3;
		if (!text.Equals(userDirectory) && !text.Equals(applicationDirectory))
		{
			string[] fileSystemEntries = Directory.GetFileSystemEntries(text);
			array3 = new string[array.Length + array2.Length + fileSystemEntries.Length];
			fileSystemEntries.CopyTo(array3, array.Length + array2.Length);
		}
		else
		{
			array3 = new string[array.Length + array2.Length];
		}
		array.CopyTo(array3, 0);
		array2.CopyTo(array3, array.Length);
		return array3;
	}

	// Token: 0x060015F2 RID: 5618 RVA: 0x0008EB84 File Offset: 0x0008CD84
	public string[] GetListSavedFiles()
	{
		string[] fileSystemEntries = Directory.GetFileSystemEntries(this.folderSaves);
		for (int i = 0; i < fileSystemEntries.Length; i++)
		{
			string[] array = fileSystemEntries[i].Split(new char[]
			{
				Path.DirectorySeparatorChar
			});
			fileSystemEntries[i] = array[array.Length - 1].Replace(".save", string.Empty);
		}
		return fileSystemEntries;
	}

	// Token: 0x060015F3 RID: 5619 RVA: 0x0008EBE2 File Offset: 0x0008CDE2
	public Sprite[] GetFemaleMicroThumbnails()
	{
		return this.femaleMicroThumbnailList.ToArray();
	}

	// Token: 0x060015F4 RID: 5620 RVA: 0x0008EBEF File Offset: 0x0008CDEF
	public Sprite[] GetMaleMicroThumbnails()
	{
		return this.maleMicroThumbnailList.ToArray();
	}

	// Token: 0x060015F5 RID: 5621 RVA: 0x0008EBFC File Offset: 0x0008CDFC
	private List<string> GetListMicroModels(List<IOManager.AssetLocationWrapper> files, Dictionary<string, string> mapping)
	{
		List<string> list = new List<string>();
		foreach (IOManager.AssetLocationWrapper assetLocationWrapper in files)
		{
			if (assetLocationWrapper.Value.EndsWith(".micro"))
			{
				AssetBundle assetBundle = AssetBundle.LoadFromFile(assetLocationWrapper.Value);
				if (assetBundle != null)
				{
					string[] array = assetLocationWrapper.Value.Split(new char[]
					{
						Path.DirectorySeparatorChar
					});
					string path = array[array.Length - 1];
					StringHolder stringHolder = assetBundle.LoadAsset("modellist") as StringHolder;
					if (stringHolder != null)
					{
						for (int i = 0; i < stringHolder.content.Length; i++)
						{
							string path2 = stringHolder.content[i];
							string text = Path.Combine(path, path2);
							if (!mapping.ContainsKey(text))
							{
								mapping.Add(text, assetLocationWrapper.Folder);
							}
							list.Add(text);
						}
					}
					assetBundle.Unload(false);
				}
			}
		}
		return list;
	}

	// Token: 0x060015F6 RID: 5622 RVA: 0x0008ED24 File Offset: 0x0008CF24
	public List<GameObject> GetPlayerModels()
	{
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < this.playerModelList.Count; i++)
		{
			list.Add(this.LoadPlayerModel(this.playerModelList[i]));
		}
		return list;
	}

	// Token: 0x060015F7 RID: 5623 RVA: 0x0008ED6C File Offset: 0x0008CF6C
	public GameObject LoadRandomPlayerModel()
	{
		string randomPlayerModelName = this.GetRandomPlayerModelName();
		return this.LoadPlayerModel(randomPlayerModelName);
	}

	// Token: 0x060015F8 RID: 5624 RVA: 0x0008ED88 File Offset: 0x0008CF88
	public string GetRandomPlayerModelName()
	{
		int index = UnityEngine.Random.Range(0, this.playerModelList.Count);
		return this.playerModelList[index];
	}

	// Token: 0x060015F9 RID: 5625 RVA: 0x0008EDB4 File Offset: 0x0008CFB4
	public GameObject LoadPlayerModel(string name)
	{
		if (name == null || name.Length == 0)
		{
			return null;
		}
		Debug.Log("Loading Player: " + name);
		if (!this.playerModelList.Contains(name))
		{
			Debug.LogWarning(name + " model is not available in this computer.");
			return null;
		}
		string[] array = name.Split(new char[]
		{
			Path.DirectorySeparatorChar
		});
		string path = array[0];
		string modelName = array[1];
		string bundlePath = Path.Combine(this.PlayerAssetMapping[name], path);
		IOManager.ModelData modelData = this.LoadModel(bundlePath, modelName);
		if (modelData != null)
		{
			modelData.model.name = name;
			IOManager.SetRenderingLayer(modelData.model, Layers.playerLayer);
			Animator component = modelData.model.GetComponent<Animator>();
			AnimationManager.SetAnimatorController(component, this.playerAnimatorController);
			return modelData.model;
		}
		Debug.LogError("Player could not be loaded from asset bundle: " + name);
		return null;
	}

	// Token: 0x060015FA RID: 5626 RVA: 0x0008EEA0 File Offset: 0x0008D0A0
	private List<string> GetGiantessModelList(List<IOManager.AssetLocationWrapper> files)
	{
		List<string> list = new List<string>();
		this.giantessThumbnailList = this.GetThumbnails(files, ".gts", this.GiantessAssetMapping);
		foreach (Sprite sprite in this.giantessThumbnailList)
		{
			list.Add(sprite.name);
			this.hashGiantess[ObjectManager.GetHash(sprite.name)] = sprite.name;
			this.hashPlayableGiantess[ObjectManager.GetHash(sprite.name + "_")] = sprite.name;
		}
		return list;
	}

	// Token: 0x060015FB RID: 5627 RVA: 0x0008EF64 File Offset: 0x0008D164
	public GameObject LoadGiantessModel(string name)
	{
		if (!this.gtsModelList.Contains(name))
		{
			Debug.LogError("Model not found: " + name);
			return null;
		}
		string[] array = name.Split(new char[]
		{
			Path.DirectorySeparatorChar
		});
		string path = array[0];
		string modelName = array[1];
		string bundlePath = Path.Combine(this.GiantessAssetMapping[name], path);
		IOManager.ModelData modelData = this.LoadModel(bundlePath, modelName);
		if (modelData != null)
		{
			modelData.model.name = name;
			IOManager.SetRenderingLayer(modelData.model, Layers.gtsBodyLayer);
			if (modelData.modelBytes != null)
			{
				MMD4MecanimModel mmd4MecanimModel = modelData.model.AddComponent<MMD4MecanimModel>();
				mmd4MecanimModel.indexFile = modelData.indexBytes;
				mmd4MecanimModel.modelFile = modelData.modelBytes;
				mmd4MecanimModel.vertexFile = modelData.vertexBytes;
			}
			return modelData.model;
		}
		Debug.LogError("Could not load asset bundle: " + name);
		return null;
	}

	// Token: 0x060015FC RID: 5628 RVA: 0x0008F05B File Offset: 0x0008D25B
	public Sprite[] GetGtsThumbnails()
	{
		return this.giantessThumbnailList.ToArray();
	}

	// Token: 0x060015FD RID: 5629 RVA: 0x0008F068 File Offset: 0x0008D268
	private List<string> GetObjectsModelList(List<IOManager.AssetLocationWrapper> files)
	{
		List<string> list = new List<string>();
		this.objectThumbList = this.GetThumbnails(files, ".object", this.ObjectAssetMapping);
		foreach (Sprite sprite in this.objectThumbList)
		{
			list.Add(sprite.name);
			this.hashObjects[ObjectManager.GetHash(sprite.name)] = sprite.name;
		}
		return list;
	}

	// Token: 0x060015FE RID: 5630 RVA: 0x0008F104 File Offset: 0x0008D304
	private GameObject LoadObjectModel(string name)
	{
		string[] array = name.Split(new char[]
		{
			Path.DirectorySeparatorChar
		});
		string path = array[0];
		string modelName = array[1];
		string bundlePath = Path.Combine(this.ObjectAssetMapping[name], path);
		IOManager.ModelData modelData = this.LoadModel(bundlePath, modelName);
		if (modelData != null)
		{
			modelData.model.name = name;
			IOManager.SetRenderingLayer(modelData.model, Layers.objectLayer);
			MeshFilter[] componentsInChildren = modelData.model.GetComponentsInChildren<MeshFilter>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].gameObject.layer = Layers.objectLayer;
				if (componentsInChildren[i].gameObject.GetComponent<MeshCollider>() == null)
				{
					componentsInChildren[i].gameObject.AddComponent<MeshCollider>();
				}
			}
			return modelData.model;
		}
		Debug.LogError("Could not load object from asset bundle: " + name);
		return null;
	}

	// Token: 0x060015FF RID: 5631 RVA: 0x0008F1F3 File Offset: 0x0008D3F3
	public GameObject LoadObject(string id)
	{
		if (this.objectList.Contains(id))
		{
			return this.LoadObjectModel(id);
		}
		return Resources.Load<GameObject>("Stuff/" + id);
	}

	// Token: 0x06001600 RID: 5632 RVA: 0x0008F220 File Offset: 0x0008D420
	public Sprite[] GetObjectsThumbnails()
	{
		Sprite[] array = Resources.LoadAll<Sprite>("StuffThumbs");
		Sprite[] array2 = new Sprite[array.Length + this.objectList.Count];
		for (int i = 0; i < array2.Length; i++)
		{
			if (i < array.Length)
			{
				array2[i] = array[i];
			}
			else
			{
				array2[i] = this.objectThumbList[i - array.Length];
			}
		}
		return array2;
	}

	// Token: 0x06001601 RID: 5633 RVA: 0x0008F28C File Offset: 0x0008D48C
	private void LoadModelShaders(GameObject model, string[] shaderList)
	{
		Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>();
		int num = 0;
		foreach (Renderer renderer in componentsInChildren)
		{
			foreach (Material material in renderer.sharedMaterials)
			{
				if (num >= shaderList.Length)
				{
					break;
				}
				if (shaderList[num].StartsWith("MMD"))
				{
					Debug.LogWarning(string.Concat(new string[]
					{
						"Model: '",
						model.name,
						"' Material: '",
						material.name,
						"' is using deprecated shader '",
						shaderList[num],
						"' consider re-exporting this model with another shader"
					}));
				}
				ShaderLoader.SetShaderOnMaterial(material, shaderList[num]);
				num++;
			}
		}
	}

	// Token: 0x06001602 RID: 5634 RVA: 0x0008F360 File Offset: 0x0008D560
	public static void SetRenderingLayer(GameObject go, LayerMask layer)
	{
		Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			componentsInChildren[i].gameObject.layer = layer;
		}
	}

	// Token: 0x06001603 RID: 5635 RVA: 0x0008F39C File Offset: 0x0008D59C
	private List<Sprite> GetThumbnails(List<IOManager.AssetLocationWrapper> files, string extension, Dictionary<string, string> mapping)
	{
		List<Sprite> list = new List<Sprite>();
		foreach (IOManager.AssetLocationWrapper assetLocationWrapper in files)
		{
			if (assetLocationWrapper.Value.EndsWith(extension))
			{
				AssetBundle assetBundle = AssetBundle.LoadFromFile(assetLocationWrapper.Value);
				if (assetBundle != null)
				{
					try
					{
						string[] array = assetLocationWrapper.Value.Split(new char[]
						{
							Path.DirectorySeparatorChar
						});
						string text = array[array.Length - 1];
						StringHolder stringHolder = assetBundle.LoadAsset("modellist") as StringHolder;
						if (stringHolder != null)
						{
							for (int i = 0; i < stringHolder.content.Length; i++)
							{
								string text2 = stringHolder.content[i];
								string text3 = Path.Combine(text, text2);
								Texture2D texture2D = assetBundle.LoadAsset(text2 + "Thumb") as Texture2D;
								if (texture2D != null)
								{
									Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), Vector2.zero);
									sprite.name = text3;
									if (!mapping.ContainsKey(text3))
									{
										mapping.Add(text3, assetLocationWrapper.Folder);
									}
									list.Add(sprite);
								}
								else
								{
									Debug.LogError("Error loading the texture of the model " + text2);
								}
							}
						}
						RuntimeAnimatorController runtimeAnimatorController = assetBundle.LoadAsset<RuntimeAnimatorController>("animationController");
						if (runtimeAnimatorController)
						{
							Debug.Log("Animator controller found in " + text);
							AnimationClip[] animationClips = runtimeAnimatorController.animationClips;
							foreach (AnimationClip animationClip in animationClips)
							{
								this.animationControllers[animationClip.name] = runtimeAnimatorController;
							}
						}
						assetBundle.Unload(false);
					}
					catch (Exception exception)
					{
						Debug.LogException(exception, this);
						Debug.LogError("Error loading model: " + assetLocationWrapper);
					}
				}
			}
		}
		return list;
	}

	// Token: 0x06001604 RID: 5636 RVA: 0x0008F5E8 File Offset: 0x0008D7E8
	public static void AddIf(List<string> list, string path)
	{
		if (path != null)
		{
			list.Add(path);
		}
	}

	// Token: 0x06001605 RID: 5637 RVA: 0x0008F5F8 File Offset: 0x0008D7F8
	public static string GetUserDirectory(string path, bool write = false)
	{
		string text = Application.persistentDataPath + Path.DirectorySeparatorChar;
		text = Path.Combine(text, path);
		text += Path.DirectorySeparatorChar;
		if (!Directory.Exists(text))
		{
			if (!write)
			{
				return null;
			}
			Directory.CreateDirectory(text);
		}
		return text;
	}

	// Token: 0x06001606 RID: 5638 RVA: 0x0008F654 File Offset: 0x0008D854
	public static string GetApplicationDirectory(string path)
	{
		string text = Path.Combine(Application.dataPath, ".." + Path.DirectorySeparatorChar);
		text = Path.Combine(text, path);
		text += Path.DirectorySeparatorChar;
		if (!Directory.Exists(text))
		{
			try
			{
				Directory.CreateDirectory(text);
			}
			catch (Exception ex)
			{
				Debug.LogWarning("Couldn't create folder '" + text + "' " + ex.ToString());
				return null;
			}
			return text;
		}
		return text;
	}

	// Token: 0x06001607 RID: 5639 RVA: 0x0008F6E8 File Offset: 0x0008D8E8
	public string[] GetAnimationList()
	{
		if (this.animationList == null)
		{
			ICollection keys = this.animationControllers.Keys;
			this.animationList = new string[keys.Count];
			keys.CopyTo(this.animationList, 0);
			Array.Sort<string>(this.animationList);
		}
		return this.animationList;
	}

	// Token: 0x06001608 RID: 5640 RVA: 0x0008F73C File Offset: 0x0008D93C
	public void SaveSettings(LuaBehavior behavior)
	{
		string file = Path.Combine(this.folderConfig, behavior.GetName() + "-config.xml");
		using (XmlWriter writer = XmlWriter.Create(file))
		{
			writer.WriteWhitespace("\r\n");
			writer.WriteStartElement("config");
			writer.WriteAttributeString("version", this.settingsConfigVersion);
			writer.WriteWhitespace("\r\n\t");
			writer.WriteStartElement("enabled");
			writer.WriteAttributeString("value", behavior.enabled.ToString());
			writer.WriteEndElement();
			writer.WriteWhitespace("\r\n\t");
			writer.WriteStartElement("canUseAI");
			writer.WriteAttributeString("value", behavior.CanUseAI().ToString());
			writer.WriteEndElement();
			writer.WriteWhitespace("\r\n\t");
			writer.WriteStartElement("ai");
			writer.WriteAttributeString("value", behavior.IsAI().ToString());
			writer.WriteEndElement();
			behavior.settings.ForEach(delegate(LuaBehavior.BehaviorSetting setting)
			{
				writer.WriteWhitespace("\r\n\t");
				writer.WriteStartElement("setting");
				writer.WriteAttributeString("name", setting.varName);
				writer.WriteAttributeString("value", setting.value.ToPrintString());
				writer.WriteEndElement();
			});
			writer.WriteWhitespace("\r\n");
			writer.WriteEndElement();
			writer.Close();
		}
	}

	// Token: 0x06001609 RID: 5641 RVA: 0x0008F90C File Offset: 0x0008DB0C
	public void LoadSettings(LuaBehavior behavior)
	{
		string text = Path.Combine(this.folderConfig, behavior.GetName() + "-config.xml");
		if (!File.Exists(text))
		{
			return;
		}
		using (XmlReader xmlReader = XmlReader.Create(text))
		{
			while (xmlReader.Read())
			{
				if (xmlReader.NodeType == XmlNodeType.Element)
				{
					if (xmlReader.Name == "config")
					{
						if (xmlReader.GetAttribute("version") != this.settingsConfigVersion)
						{
							Debug.LogWarning("Behavior \"" + behavior.GetText() + "\" config file outdated; not loading");
							break;
						}
					}
					else if (xmlReader.Name == "setting")
					{
						for (int i = 0; i < behavior.settings.Count; i++)
						{
							LuaBehavior.BehaviorSetting value = behavior.settings[i];
							if (!(value.varName != xmlReader.GetAttribute("name")))
							{
								switch (value.type)
								{
								case LuaBehavior.BehaviorSettingType.Bool:
									value.value = DynValue.NewBoolean(bool.Parse(xmlReader.GetAttribute("value")));
									break;
								case LuaBehavior.BehaviorSettingType.String:
									value.value = DynValue.NewString(xmlReader.GetAttribute("value"));
									break;
								case LuaBehavior.BehaviorSettingType.Float:
									value.value = DynValue.NewNumber(double.Parse(xmlReader.GetAttribute("value")));
									break;
								case LuaBehavior.BehaviorSettingType.Array:
									value.value = DynValue.NewNumber((double)int.Parse(xmlReader.GetAttribute("value")));
									break;
								}
								behavior.settings[i] = value;
							}
						}
					}
					else if (xmlReader.Name == "enabled")
					{
						behavior.enabled = bool.Parse(xmlReader.GetAttribute("value"));
					}
					else if (xmlReader.Name == "canUseAI")
					{
						behavior.canUseAi = bool.Parse(xmlReader.GetAttribute("value"));
					}
					else if (xmlReader.Name == "ai")
					{
						bool flag = bool.Parse(xmlReader.GetAttribute("value"));
						if (!behavior.CanUseAI() && flag)
						{
							Debug.LogWarning("Behavior \"" + behavior.GetText() + "\" is not setup to use AI.");
						}
						else
						{
							behavior.ai = flag;
						}
					}
				}
			}
		}
	}

	// Token: 0x0600160A RID: 5642 RVA: 0x0008FBC4 File Offset: 0x0008DDC4
	private IEnumerator LoadSoundFiles()
	{
		this.audioLoader.SearchAndLoadClips(this.folderSounds);
		yield return null;
		yield break;
	}

	// Token: 0x0600160B RID: 5643 RVA: 0x0008FBDF File Offset: 0x0008DDDF
	public AudioClip LoadAudioClip(string clipName)
	{
		return this.audioLoader.LoadAudioClip(clipName);
	}

	// Token: 0x0600160C RID: 5644 RVA: 0x0008FBED File Offset: 0x0008DDED
	public IList<string> GetPlayerModelList()
	{
		return this.playerModelList.AsReadOnly();
	}

	// Token: 0x0600160D RID: 5645 RVA: 0x0008FBFA File Offset: 0x0008DDFA
	public IList<string> GetGtsModelList()
	{
		return this.gtsModelList.AsReadOnly();
	}

	// Token: 0x0600160E RID: 5646 RVA: 0x0008FC07 File Offset: 0x0008DE07
	public IList<string> GetFemaleMicroList()
	{
		return this.femaleMicroList.AsReadOnly();
	}

	// Token: 0x0600160F RID: 5647 RVA: 0x0008FC14 File Offset: 0x0008DE14
	public IList<string> GetMaleMicroList()
	{
		return this.maleMicroList.AsReadOnly();
	}

	// Token: 0x06001610 RID: 5648 RVA: 0x0008FC21 File Offset: 0x0008DE21
	public IList<string> GetObjectList()
	{
		return this.objectList.AsReadOnly();
	}

	// Token: 0x04001895 RID: 6293
	private string settingsConfigVersion;

	// Token: 0x04001896 RID: 6294
	private string dataCache;

	// Token: 0x04001897 RID: 6295
	private AudioLoader audioLoader;

	// Token: 0x04001898 RID: 6296
	private static IOManager _instance;

	// Token: 0x04001899 RID: 6297
	private List<string> playerModelList = new List<string>();

	// Token: 0x0400189A RID: 6298
	private List<string> gtsModelList = new List<string>();

	// Token: 0x0400189B RID: 6299
	private List<string> maleMicroList = new List<string>();

	// Token: 0x0400189C RID: 6300
	private List<string> femaleMicroList = new List<string>();

	// Token: 0x0400189D RID: 6301
	private List<string> objectList = new List<string>();

	// Token: 0x0400189E RID: 6302
	private List<Sprite> giantessThumbnailList = new List<Sprite>();

	// Token: 0x0400189F RID: 6303
	private List<Sprite> objectThumbList = new List<Sprite>();

	// Token: 0x040018A0 RID: 6304
	private List<Sprite> maleMicroThumbnailList = new List<Sprite>();

	// Token: 0x040018A1 RID: 6305
	private List<Sprite> femaleMicroThumbnailList = new List<Sprite>();

	// Token: 0x040018A2 RID: 6306
	public Dictionary<string, RuntimeAnimatorController> animationControllers;

	// Token: 0x040018A3 RID: 6307
	public Dictionary<string, string> GiantessAssetMapping;

	// Token: 0x040018A4 RID: 6308
	public Dictionary<string, string> MaleMicroAssetMapping;

	// Token: 0x040018A5 RID: 6309
	public Dictionary<string, string> FemaleMicroAssetMapping;

	// Token: 0x040018A6 RID: 6310
	public Dictionary<string, string> PlayerAssetMapping;

	// Token: 0x040018A7 RID: 6311
	public Dictionary<string, string> ObjectAssetMapping;

	// Token: 0x040018A8 RID: 6312
	private string[] animationList;

	// Token: 0x040018A9 RID: 6313
	private List<string> folderGTSModels;

	// Token: 0x040018AA RID: 6314
	private List<string> folderPlayerModels;

	// Token: 0x040018AB RID: 6315
	private List<string> folderMaleNPC;

	// Token: 0x040018AC RID: 6316
	private List<string> folderFemaleNPC;

	// Token: 0x040018AD RID: 6317
	private List<string> folderObjects;

	// Token: 0x040018AE RID: 6318
	private List<string> folderSounds;

	// Token: 0x040018AF RID: 6319
	public RuntimeAnimatorController microAnimatorController;

	// Token: 0x040018B0 RID: 6320
	public RuntimeAnimatorController playerAnimatorController;

	// Token: 0x040018B1 RID: 6321
	public RuntimeAnimatorController gtsPlayerAnimatorController;

	// Token: 0x040018B2 RID: 6322
	public RuntimeAnimatorController poseAnimatorController;

	// Token: 0x040018B3 RID: 6323
	public RuntimeAnimatorController gtsAnimatorController;

	// Token: 0x040018B4 RID: 6324
	public HashSet<string> poses;

	// Token: 0x040018B5 RID: 6325
	public List<string> posesList;

	// Token: 0x040018B6 RID: 6326
	private string folderSaves;

	// Token: 0x040018B7 RID: 6327
	private string folderScreenshots;

	// Token: 0x040018B8 RID: 6328
	private string folderConfig;

	// Token: 0x040018B9 RID: 6329
	public Dictionary<NetworkHash128, string> hashPlayer;

	// Token: 0x040018BA RID: 6330
	public Dictionary<NetworkHash128, string> hashObjects;

	// Token: 0x040018BB RID: 6331
	public Dictionary<NetworkHash128, string> hashGiantess;

	// Token: 0x040018BC RID: 6332
	public Dictionary<NetworkHash128, string> hashPlayableGiantess;

	// Token: 0x040018BD RID: 6333
	public bool isLoadingData;

	// Token: 0x040018BE RID: 6334
	public static Shader standard2SidedShader;

	// Token: 0x0200034D RID: 845
	public class ModelData
	{
		// Token: 0x040018BF RID: 6335
		public GameObject model;

		// Token: 0x040018C0 RID: 6336
		public TextAsset modelBytes;

		// Token: 0x040018C1 RID: 6337
		public TextAsset indexBytes;

		// Token: 0x040018C2 RID: 6338
		public TextAsset vertexBytes;
	}

	// Token: 0x0200034E RID: 846
	public class AnimationData
	{
		// Token: 0x06001612 RID: 5650 RVA: 0x0008FC2E File Offset: 0x0008DE2E
		public AnimationData(string s, string i)
		{
			this.showName = s;
			this.internalName = i;
		}

		// Token: 0x040018C3 RID: 6339
		public string showName;

		// Token: 0x040018C4 RID: 6340
		public string internalName;
	}

	// Token: 0x0200034F RID: 847
	public class AssetLocationWrapper
	{
		// Token: 0x06001613 RID: 5651 RVA: 0x0008FC44 File Offset: 0x0008DE44
		public AssetLocationWrapper(string value, string folder)
		{
			this.Value = value;
			this.Folder = folder;
		}

		// Token: 0x17000376 RID: 886
		// (get) Token: 0x06001614 RID: 5652 RVA: 0x0008FC5A File Offset: 0x0008DE5A
		// (set) Token: 0x06001615 RID: 5653 RVA: 0x0008FC62 File Offset: 0x0008DE62
		public string Value { get; set; }

		// Token: 0x17000377 RID: 887
		// (get) Token: 0x06001616 RID: 5654 RVA: 0x0008FC6B File Offset: 0x0008DE6B
		// (set) Token: 0x06001617 RID: 5655 RVA: 0x0008FC73 File Offset: 0x0008DE73
		public string Folder { get; set; }
	}
}
